#include "lolevel.h"
#include "platform.h"
#include "core.h"

static long *nrflag = (long*)0x7FD0; /* S90 above "aShuttersoundta" usage @FF966918 @101a */

#include "../../../generic/capt_seq.c"

void __attribute__((naked,noinline)) capt_seq_task() {
 asm volatile (
        "STMFD   SP!, {R3-R9,LR}\n"
        "LDR     R6, =0x2C58\n"
        "LDR     R4, =0x39F60\n"
        "MOV     R9, #1\n"
        "MOV     R7, #0\n"
"loc_FF87A21C:\n"
        "LDR     R0, [R6,#4]\n"
        "MOV     R2, #0\n"
        "MOV     R1, SP\n"
        "BL      sub_FF8382FC    \n"
        "TST     R0, #1\n"
        "BEQ     loc_FF87A248\n"
        "LDR     R1, =0x5B3\n"
        "LDR     R0, =0xFF879A2C\n"
        "BL      sub_FF81E88C\n"
        "BL      sub_FF81E844    \n"
        "LDMFD   SP!, {R3-R9,PC}\n"
"loc_FF87A248:\n"
        "LDR     R0, [SP]\n"
        "LDR     R1, [R0]\n"
        "CMP     R1, #0x21\n"
        "ADDLS   PC, PC, R1,LSL#2\n"
        "B       loc_FF87A50C\n"
"loc_FF87A25C:\n"
        "B       loc_FF87A2E4\n"
"loc_FF87A260:\n"
        "B       loc_FF87A350\n"
"loc_FF87A264:\n"
        "B       loc_FF87A38C\n"
"loc_FF87A268:\n"
        "B       loc_FF87A3A0\n"
"loc_FF87A26C:\n"
        "B       loc_FF87A398\n"
"loc_FF87A270:\n"
        "B       loc_FF87A3A8\n"
"loc_FF87A274:\n"
        "B       loc_FF87A3B0\n"
"loc_FF87A278:\n"
        "B       loc_FF87A3B8\n"
"loc_FF87A27C:\n"
        "B       loc_FF87A410\n"
"loc_FF87A280:\n"
        "B       loc_FF87A438\n"
"loc_FF87A284:\n"
        "B       loc_FF87A41C\n"
"loc_FF87A288:\n"
        "B       loc_FF87A428\n"
"loc_FF87A28C:\n"
        "B       loc_FF87A430\n"
"loc_FF87A290:\n"
        "B       loc_FF87A440\n"
"loc_FF87A294:\n"
        "B       loc_FF87A448\n"
"loc_FF87A298:\n"
        "B       loc_FF87A450\n"
"loc_FF87A29C:\n"
        "B       loc_FF87A458\n"
"loc_FF87A2A0:\n"
        "B       loc_FF87A460\n"
"loc_FF87A2A4:\n"
        "B       loc_FF87A468\n"
"loc_FF87A2A8:\n"
        "B       loc_FF87A470\n"
"loc_FF87A2AC:\n"
        "B       loc_FF87A478\n"
"loc_FF87A2B0:\n"
        "B       loc_FF87A480\n"
"loc_FF87A2B4:\n"
        "B       loc_FF87A488\n"
"loc_FF87A2B8:\n"
        "B       loc_FF87A494\n"
"loc_FF87A2BC:\n"
        "B       loc_FF87A49C\n"
"loc_FF87A2C0:\n"
        "B       loc_FF87A4A8\n"
"loc_FF87A2C4:\n"
        "B       loc_FF87A4B0\n"
"loc_FF87A2C8:\n"
        "B       loc_FF87A4B8\n"
"loc_FF87A2CC:\n"
        "B       loc_FF87A4C0\n"
"loc_FF87A2D0:\n"
        "B       loc_FF87A4C8\n"
"loc_FF87A2D4:\n"
        "B       loc_FF87A4D0\n"
"loc_FF87A2D8:\n"
        "B       loc_FF87A4D8\n"
"loc_FF87A2DC:\n"
        "B       loc_FF87A4E4\n"
"loc_FF87A2E0:\n"
        "B       loc_FF87A518\n"
"loc_FF87A2E4:\n"
        "BL      sub_FF87AB20\n"
		"BL      shooting_expo_param_override\n"  // + 
        "BL      sub_FF877B70\n"
// copied over from SX10 don't know if we need it yet
//  this code added to avoid some incorrect behavior if overrides are used.
//  but it can cause some unexpected side effects. In this case, remove this code!
                 "MOV     R0, #0\n"
                 "STR     R0, [R4,#0x24]\n"  // fixes overrides  behavior at short shutter press
 //  end of my code
 
        "LDR     R0, [R4,#0x24]\n"
        "CMP     R0, #0\n"
        "BEQ     loc_FF87A518\n"
        "BL      sub_FF879700\n"
        "MOV     R5, R0\n"
        "LDR     R0, [R4,#0x24]\n"
        "CMP     R0, #0\n"
        "BEQ     loc_FF87A32C\n"
        "MOV     R0, #0xC\n"
        "BL      sub_FF87F958\n"
        "TST     R0, #1\n"
        "STRNE   R9, [R6,#0x10]\n"
        "LDRNE   R0, [R5,#8]\n"
        "ORRNE   R0, R0, #0x40000000\n"
        "STRNE   R0, [R5,#8]\n"
        "BNE     loc_FF87A518\n"
"loc_FF87A32C:\n"
        "MOV     R0, R5\n"
        "BL      sub_FF966068\n"
        "MOV     R0, R5\n"
        "BL      sub_FF879AE0\n"
        "MOV     R0, R5\n"
        //"BL      sub_FF966904    \n"
		"BL      sub_FF966904_my\n" // -------------->
		"BL      capt_seq_hook_raw_here\n"      // +
        "TST     R0, #1\n"
        "STRNE   R9, [R6,#0x10]\n"
        "B       loc_FF87A518\n"
"loc_FF87A350:\n"
        "LDR     R0, [R4,#0x24]\n"
        "CMP     R0, #0\n"
        "BNE     loc_FF87A37C\n"
        "MOV     R0, #0xC\n"
        "BL      sub_FF87F958\n"
        "TST     R0, #1\n"
        "LDRNE   R0, [SP]\n"
        "MOVNE   R1, #1\n"
        "LDRNE   R2, [R0,#0xC]\n"
        "MOVNE   R0, #1\n"
        "BNE     loc_FF87A408\n"
"loc_FF87A37C:\n"
        "LDR     R0, [SP]\n"
        //"BL      sub_FF879B58\n" //- capt_seq_hook ist called in this subroutine
		"BL      sub_FF879B58_my\n" //---------->
"loc_FF87A384:\n"
        "STR     R7, [R4,#0x24]\n"
        "B       loc_FF87A518\n"
"loc_FF87A38C:\n"
        "MOV     R0, #1\n"
        "BL      sub_FF87AD74    \n"
        "B       loc_FF87A518\n"
"loc_FF87A398:\n"
        "BL      sub_FF87A7D0\n"
        "B       loc_FF87A384\n"
"loc_FF87A3A0:\n"
        "BL      sub_FF87AB00\n"
        "B       loc_FF87A384\n"
"loc_FF87A3A8:\n"
        "BL      sub_FF87AB08\n"
        "B       loc_FF87A518\n"
"loc_FF87A3B0:\n"
        "BL      sub_FF87AC94\n"
        "B       loc_FF87A414\n"
"loc_FF87A3B8:\n"
        "LDR     R5, [R0,#0xC]\n"
        "BL      sub_FF87AB10\n"
        "MOV     R0, R5\n"
        "BL      sub_FF9654F4    \n"
        "TST     R0, #1\n"
        "MOV     R8, R0\n"
        "BNE     loc_FF87A3F8\n"
        "BL      sub_FF88CC20    \n"
        "STR     R0, [R5,#0x18]\n"
        "MOV     R0, R5\n"
        "BL      sub_FF96681C    \n"
        "MOV     R0, R5\n"
        "BL      sub_FF966C1C    \n"
        "MOV     R8, R0\n"
        "LDR     R0, [R5,#0x18]\n"
        "BL      sub_FF88CE34    \n"
"loc_FF87A3F8:\n"
        "BL      sub_FF87AB00\n"
        "MOV     R2, R5\n"
        "MOV     R1, #9\n"
        "MOV     R0, R8\n"
"loc_FF87A408:\n"
        "BL      sub_FF8780D8    \n"
        "B       loc_FF87A518\n"
"loc_FF87A410:\n"
        "BL      sub_FF87ACF4\n"
"loc_FF87A414:\n"
        "BL      sub_FF877B70\n"
        "B       loc_FF87A518\n"
"loc_FF87A41C:\n"
        "LDR     R0, [R4,#0x54]\n"
        "BL      sub_FF87B5D4    \n"
        "B       loc_FF87A518\n"
"loc_FF87A428:\n"
        "BL      sub_FF87B888\n"
        "B       loc_FF87A518\n"
"loc_FF87A430:\n"
        "BL      sub_FF87B91C\n"
        "B       loc_FF87A518\n"
"loc_FF87A438:\n"
        "BL      sub_FF87AB00\n"
        "B       loc_FF87A518\n"
"loc_FF87A440:\n"
        "BL      sub_FF965710\n"
        "B       loc_FF87A518\n"
"loc_FF87A448:\n"
        "BL      sub_FF965924\n"
        "B       loc_FF87A518\n"
"loc_FF87A450:\n"
        "BL      sub_FF9659AC\n"
        "B       loc_FF87A518\n"
"loc_FF87A458:\n"
        "BL      sub_FF965A9C\n"
        "B       loc_FF87A518\n"
"loc_FF87A460:\n"
        "BL      sub_FF965B90\n"
        "B       loc_FF87A518\n"
"loc_FF87A468:\n"
        "MOV     R0, #0\n"
        "B       loc_FF87A48C\n"
"loc_FF87A470:\n"
        "BL      sub_FF965DAC\n"
        "B       loc_FF87A518\n"
"loc_FF87A478:\n"
        "BL      sub_FF965E3C\n"
        "B       loc_FF87A518\n"
"loc_FF87A480:\n"
        "BL      sub_FF965EFC\n"
        "B       loc_FF87A518\n"
"loc_FF87A488:\n"
        "MOV     R0, #1\n"
"loc_FF87A48C:\n"
        "BL      sub_FF965C5C\n"
        "B       loc_FF87A518\n"
"loc_FF87A494:\n"
        "BL      sub_FF87AF5C\n"
        "B       loc_FF87A518\n"
"loc_FF87A49C:\n"
        "BL      sub_FF87AFFC\n"
        "BL      sub_FF87A640    \n"
        "B       loc_FF87A518\n"
"loc_FF87A4A8:\n"
        "BL      sub_FF87B370\n"
        "B       loc_FF87A518\n"
"loc_FF87A4B0:\n"
        "BL      sub_FF87B48C\n"
        "B       loc_FF87A518\n"
"loc_FF87A4B8:\n"
        "BL      sub_FF8799B8\n"
        "B       loc_FF87A518\n"
"loc_FF87A4C0:\n"
        "BL      sub_FF835FDC\n"
        "B       loc_FF87A518\n"
"loc_FF87A4C8:\n"
        "BL      sub_FF87DCDC\n"
        "B       loc_FF87A518\n"
"loc_FF87A4D0:\n"
        "BL      sub_FF87DD44\n"
        "B       loc_FF87A518\n"
"loc_FF87A4D8:\n"
        "BL      sub_FF87DDA0\n"
        "BL      sub_FF87DD60\n"
        "B       loc_FF87A518\n"
"loc_FF87A4E4:\n"
        "MOV     R0, #1\n"
        "BL      sub_FF967484\n"
        "MOV     R0, #1\n"
        "BL      sub_FF967594\n"
        "LDRH    R0, [R4,#0xA0]\n"
        "CMP     R0, #4\n"
        "BNE     loc_FF87A518\n"
        "BL      sub_FF87DD44\n"
        "BL      sub_FF87E18C\n"
        "B       loc_FF87A518\n"
"loc_FF87A50C:\n"
        "LDR     R1, =0x708\n"
        "LDR     R0, =0xFF879A2C\n"
        "BL      sub_FF81E88C\n"
"loc_FF87A518:\n"
        "LDR     R0, [SP]\n"
        "LDR     R1, [R0,#4]\n"
        "LDR     R0, [R6]\n"
        "BL      sub_FF88490C\n"
        "LDR     R5, [SP]\n"
        "LDR     R0, [R5,#8]\n"
        "CMP     R0, #0\n"
        "LDREQ   R1, =0x131\n"
        "LDREQ   R0, =0xFF879A2C\n"
        "BLEQ    sub_FF81E88C\n"
        "STR     R7, [R5,#8]\n"
        "B       loc_FF87A21C\n"
 );
}


void __attribute__((naked,noinline)) sub_FF879B58_my() {
 asm volatile (
        "STMFD   SP!, {R3-R9,LR}\n"
        "LDR     R4, [R0,#0xC]\n"
        "LDR     R5, =0x39F60\n"
        "LDR     R0, [R4,#8]\n"
        "LDR     R6, =0x420A\n"
        "ORR     R0, R0, #1\n"
        "STR     R0, [R4,#8]\n"
        "LDRH    R0, [R5]\n"
        "LDR     R8, =0x2C58\n"
        "MOV     R7, #0\n"
        "CMP     R0, R6\n"
        "BEQ     loc_FF879BFC\n"
        "LDRH    R0, [R5,#0x9E]\n"
        "CMP     R0, #3\n"
        "BEQ     loc_FF879C5C\n"
        "LDR     R0, [R4,#0xC]\n"
        "CMP     R0, #1\n"
        "BLS     loc_FF879C08\n"
        "LDRH    R0, [R5,#0x9C]\n"
        "CMP     R0, #0\n"
        "BNE     loc_FF879C5C\n"
        "LDRH    R0, [R5,#0x98]\n"
        "CMP     R0, #2\n"
        "BNE     loc_FF879C14\n"
        "BL      sub_FF87B0AC\n"
        "LDRH    R0, [R5]\n"
        "CMP     R0, R6\n"
        "BEQ     loc_FF879BFC\n"
        "LDRH    R0, [R5,#0x9E]\n"
        "CMP     R0, #3\n"
        "BEQ     loc_FF879C5C\n"
        "LDR     R0, [R4,#0xC]\n"
        "CMP     R0, #1\n"
        "BLS     loc_FF879C08\n"
        "LDRH    R0, [R5,#0x9C]\n"
        "CMP     R0, #0\n"
        "BNE     loc_FF879C5C\n"
        "LDRH    R0, [R5,#0x98]\n"
        "CMP     R0, #2\n"
        "BEQ     loc_FF879C40\n"
        "B       loc_FF879C14\n"
"loc_FF879BFC:\n"
        "LDRH    R0, [R5,#0x9E]\n"
        "CMP     R0, #3\n"
        "BEQ     loc_FF879C5C\n"
"loc_FF879C08:\n"
        "LDRH    R0, [R5,#0x9C]\n"
        "CMP     R0, #0\n"
        "BNE     loc_FF879C5C\n"
"loc_FF879C14:\n"
        "LDRH    R0, [R5,#0x98]\n"
        "CMP     R0, #1\n"
        "BNE     loc_FF879C5C\n"
        "LDRH    R0, [R5]\n"
        "CMP     R0, R6\n"
        "LDRNE   R0, [R4,#0xC]\n"
        "CMPNE   R0, #1\n"
        "BLS     loc_FF879C5C\n"
        "LDR     R0, [R4,#0x10]\n"
        "CMP     R0, #1\n"
        "BNE     loc_FF879C5C\n"
"loc_FF879C40:\n"
        "MOV     R3, #0x268\n"
        "STR     R3, [SP]\n"
        "LDR     R0, [R8]\n"
        "LDR     R2, =0xEA60\n"
        //"ADR     R3, 0xFF879A2C\n"
		"LDR     R3, =0xFF879A2C\n"
        "MOV     R1, #0x40000000\n"
        "BL      sub_FF87FCB8\n"
"loc_FF879C5C:\n"
        "BL      sub_FF8799B8\n"
        "LDR     R0, [R5,#0x24]\n"
        "CMP     R0, #0\n"
        "MOVEQ   R0, #2\n"
        "BLEQ    sub_FF8762DC\n"
        "BL      sub_FF87AB10\n"
        "LDR     R0, [R5,#0x24]\n"
        "CMP     R0, #0\n"
        "BNE     loc_FF879D14\n"
        "MOV     R0, #0\n"
        "BL      sub_FF967484\n"
        "MOV     R0, #0\n"
        "BL      sub_FF967594\n"
        "MOV     R0, R4\n"
        "BL      sub_FF966068\n"
        "MOV     R0, R4\n"
        "BL      sub_FF87AED8\n"
        "MOV     R0, R4\n"
        "BL      sub_FF9650E4\n"
        "CMP     R0, #0\n"
        "BEQ     loc_FF879CDC\n"
        "BL      sub_FF9674C4\n"
        "BL      sub_FF9675D8\n"
        "BL      sub_FF967628\n"
        "MOV     R0, R4\n"
        "BL      sub_FF965228    \n"
        "TST     R0, #1\n"
        "MOVNE   R2, R4\n"
        "LDMNEFD SP!, {R3-R9,LR}\n"
        "MOVNE   R1, #1\n"
        "BNE     sub_FF8780D8    \n"
        "B       loc_FF879CF0\n"
"loc_FF879CDC:\n"
        "MOV     R0, R4\n"
        "BL      sub_FF965194\n"
        "BL      sub_FF9674C4\n"
        "BL      sub_FF9675D8\n"
        "BL      sub_FF967628\n"
"loc_FF879CF0:\n"
        "MOV     R0, R4\n"
        "BL      sub_FF879AE0\n"
        "MOV     R0, R4\n"
        "BL      sub_FF96681C    \n"
        "BL      sub_FF96729C    \n"
        "MOV     R0, R4\n"
        //"BL      sub_FF966904    \n"
		"BL      sub_FF966904_my    \n" // ---------->
        "MOV     R7, R0\n"
		"BL      capt_seq_hook_raw_here\n"      // +
        "B       loc_FF879D20\n"
"loc_FF879D14:\n"
        "LDR     R0, [R8,#0x10]\n"
        "CMP     R0, #0\n"
        "MOVNE   R7, #0x1D\n"
"loc_FF879D20:\n"
        "BL      sub_FF87DD44\n"
        "BL      sub_FF87DD8C\n"
        "BL      sub_FF87DDCC\n"
        "MOV     R2, R4\n"
        "MOV     R1, #1\n"
        "MOV     R0, R7\n"
        "BL      sub_FF8780D8    \n"
        "BL      sub_FF966BC0\n"
        "CMP     R0, #0\n"
        "LDRNE   R0, [R4,#8]\n"
        "ORRNE   R0, R0, #0x2000\n"
        "STRNE   R0, [R4,#8]\n"
        "LDRH    R0, [R5,#0x9E]\n"
        "CMP     R0, #3\n"
        "BEQ     locret_FF879D78\n"
        "LDRH    R0, [R5,#0x9C]\n"
        "CMP     R0, #0\n"
        "LDREQH  R0, [R5,#0x98]\n"
        "CMPEQ   R0, #2\n"
        "MOVEQ   R0, R4\n"
        "LDMEQFD SP!, {R3-R9,LR}\n"
        "BEQ     sub_FF87B100\n"
"locret_FF879D78:\n"
        "LDMFD   SP!, {R3-R9,PC}\n"
 );
}

void __attribute__((naked,noinline)) sub_FF966904_my() {
 asm volatile (
        "STMFD   SP!, {R0-R8,LR}\n"
        "MOV     R4, R0\n"
        "BL      sub_FF967780\n"
        "MVN     R1, #0\n"
        "BL      sub_FF884940\n"
        "LDR     R5, =0x7FD0\n"
        "LDR     R0, [R5,#0xC]\n"
        "CMP     R0, #0\n"
        "BNE     loc_FF966954\n"
        "MOV     R1, #1\n"
        "MOV     R0, #0\n"
        "BL      sub_FF838B44\n"
        "STR     R0, [R5,#0xC]\n"
        "MOV     R3, #0\n"
        "STR     R3, [SP]\n"
        "LDR     R3, =0xFF966290 \n"
        //"ADR     R0, 0xFF966B84\n"
		"LDR     R0, =0xFF966B84\n"
        "MOV     R2, #0x400\n"
        "MOV     R1, #0x17\n"
        "BL      sub_FF838B10\n"
"loc_FF966954:\n"
        "MOV     R2, #4\n"
        "ADD     R1, SP, #8\n"
        "MOV     R0, #0x8A\n"
        "BL      sub_FF88CA90\n"
        "TST     R0, #1\n"
        "LDRNE   R1, =0x3C5\n"
        "LDRNE   R0, =0xFF966528\n"
        "BLNE    sub_FF81E88C\n"
        "LDR     R6, =0x3A02C\n"
        "LDR     R8, =0x39F60\n"
        "LDR     R3, [R6]\n"
        "LDRSH   R2, [R6,#0xC]\n"
        "LDRSH   R1, [R6,#0xE]\n"
        "LDR     R0, [R8,#0x94]\n"
        "BL      sub_FF92E144\n"
        "BL      sub_FF86157C    \n"
        "LDR     R3, =0x7FD8\n"
        "STRH    R0, [R4,#0xA4]\n"
        "SUB     R2, R3, #4\n"
        "STRD    R2, [SP]\n"
        "MOV     R1, R0\n"
        "LDRH    R0, [R8,#0x5C]\n"
        "LDRSH   R2, [R6,#0xC]\n"
        "SUB     R3, R3, #8\n"
        "BL      sub_FF9694A0\n"
        "BL      wait_until_remote_button_is_released\n"  // +
        "BL      capt_seq_hook_set_nr\n"                  // +   
        "B       sub_FF9669B8\n" // +  Jump back to original FW code
 );
}

void __attribute__((naked,noinline)) exp_drv_task(){
 asm volatile(
        "STMFD   SP!, {R4-R8,LR}\n"
        "SUB     SP, SP, #0x20\n"
        "LDR     R8, =0xBB8\n"
        "LDR     R7, =0x4440\n"
        "LDR     R5, =0x4372C\n"
        "MOV     R0, #0\n"
        "ADD     R6, SP, #0x10\n"
        "STR     R0, [SP,#0xC]\n"
"loc_FF8C0EA0:\n"
        "LDR     R0, [R7,#0x20]\n"
        "MOV     R2, #0\n"
        "ADD     R1, SP, #0x1C\n"
        "BL      sub_FF8382FC    \n"
        "LDR     R0, [SP,#0xC]\n"
        "CMP     R0, #1\n"
        "BNE     loc_FF8C0EEC\n"
        "LDR     R0, [SP,#0x1C]\n"
        "LDR     R0, [R0]\n"
        "CMP     R0, #0x13\n"
        "CMPNE   R0, #0x14\n"
        "CMPNE   R0, #0x15\n"
        "CMPNE   R0, #0x16\n"
        "BEQ     loc_FF8C1050\n"
        "CMP     R0, #0x28\n"
        "BEQ     loc_FF8C0FD8\n"
        "ADD     R1, SP, #0xC\n"
        "MOV     R0, #0\n"
        "BL      sub_FF8C0E30    \n"
"loc_FF8C0EEC:\n"
        "LDR     R0, [SP,#0x1C]\n"
        "LDR     R1, [R0]\n"
        "CMP     R1, #0x2E\n"
        "BNE     loc_FF8C0F1C\n"
        "LDR     R0, [SP,#0x1C]\n"
        "BL      sub_FF8C2188    \n"
        "LDR     R0, [R7,#0x1C]\n"
        "MOV     R1, #1\n"
        "BL      sub_FF88490C\n"
        "BL      sub_FF81E844    \n"
        "ADD     SP, SP, #0x20\n"
        "LDMFD   SP!, {R4-R8,PC}\n"
"loc_FF8C0F1C:\n"
        "CMP     R1, #0x2D\n"
        "BNE     loc_FF8C0F38\n"
        "LDR     R2, [R0,#0x8C]!\n"
        "LDR     R1, [R0,#4]\n"
        "MOV     R0, R1\n"
        "BLX     R2\n"
        "B       loc_FF8C1478\n"
"loc_FF8C0F38:\n"
        "CMP     R1, #0x26\n"
        "BNE     loc_FF8C0F88\n"
        "LDR     R0, [R7,#0x1C]\n"
        "MOV     R1, #0x80\n"
        "BL      sub_FF884940\n"
        "LDR     R0, =0xFF8BD5C8\n"
        "MOV     R1, #0x80\n"
        "BL      sub_FF959550    \n"
        "LDR     R0, [R7,#0x1C]\n"
        "MOV     R2, R8\n"
        "MOV     R1, #0x80\n"
        "BL      sub_FF88484C    \n"
        "TST     R0, #1\n"
        "LDRNE   R1, =0xE5F\n"
        "BNE     loc_FF8C1044\n"
"loc_FF8C0F74:\n"
        "LDR     R1, [SP,#0x1C]\n"
        "LDR     R0, [R1,#0x90]\n"
        "LDR     R1, [R1,#0x8C]\n"
        "BLX     R1\n"
        "B       loc_FF8C1478\n"
"loc_FF8C0F88:\n"
        "CMP     R1, #0x27\n"
        "BNE     loc_FF8C0FD0\n"
        "ADD     R1, SP, #0xC\n"
        "BL      sub_FF8C0E30    \n"
        "LDR     R0, [R7,#0x1C]\n"
        "MOV     R1, #0x100\n"
        "BL      sub_FF884940\n"
        "LDR     R0, =0xFF8BD5D8\n"
        "MOV     R1, #0x100\n"
        "BL      sub_FF959EE0    \n"
        "LDR     R0, [R7,#0x1C]\n"
        "MOV     R2, R8\n"
        "MOV     R1, #0x100\n"
        "BL      sub_FF88484C    \n"
        "TST     R0, #1\n"
        "BEQ     loc_FF8C0F74\n"
        "LDR     R1, =0xE69\n"
        "B       loc_FF8C1044\n"
"loc_FF8C0FD0:\n"
        "CMP     R1, #0x28\n"
        "BNE     loc_FF8C0FE8\n"
"loc_FF8C0FD8:\n"
        "LDR     R0, [SP,#0x1C]\n"
        "ADD     R1, SP, #0xC\n"
        "BL      sub_FF8C0E30    \n"
        "B       loc_FF8C0F74\n"
"loc_FF8C0FE8:\n"
        "CMP     R1, #0x2B\n"
        "BNE     loc_FF8C1000\n"
        "BL      sub_FF8B0A2C    \n"
        "BL      sub_FF8B1650    \n"
        "BL      sub_FF8B11A4    \n"
        "B       loc_FF8C0F74\n"
"loc_FF8C1000:\n"
        "CMP     R1, #0x2C\n"
        "BNE     loc_FF8C1050\n"
        "LDR     R0, [R7,#0x1C]\n"
        "MOV     R1, #4\n"
        "BL      sub_FF884940\n"
        "LDR     R1, =0xFF8BD5F8\n"
        "LDR     R0, =0xFFFFF400\n"
        "MOV     R2, #4\n"
        "BL      sub_FF8B04A8\n"
        "BL      sub_FF8B0730    \n"
        "LDR     R0, [R7,#0x1C]\n"
        "MOV     R2, R8\n"
        "MOV     R1, #4\n"
        "BL      sub_FF884768    \n"
        "TST     R0, #1\n"
        "BEQ     loc_FF8C0F74\n"
        "LDR     R1, =0xE91\n"
"loc_FF8C1044:\n"
        "LDR     R0, =0xFF8BDC38\n"
        "BL      sub_FF81E88C\n"
        "B       loc_FF8C0F74\n"
"loc_FF8C1050:\n"
        "LDR     R0, [SP,#0x1C]\n"
        "MOV     R4, #1\n"
        "LDR     R1, [R0]\n"
        "CMP     R1, #0x11\n"
        "CMPNE   R1, #0x12\n"
        "BNE     loc_FF8C10C0\n"
        "LDR     R1, [R0,#0x7C]\n"
        "ADD     R1, R1, R1,LSL#1\n"
        "ADD     R1, R0, R1,LSL#2\n"
        "SUB     R1, R1, #8\n"
        "LDMIA   R1, {R2-R4}\n"
        "STMIA   R6, {R2-R4}\n"
        "BL      sub_FF8BF7B0\n"
        "LDR     R0, [SP,#0x1C]\n"
        "LDR     R1, [R0,#0x7C]\n"
        "LDR     R3, [R0,#0x8C]\n"
        "LDR     R2, [R0,#0x90]\n"
        "ADD     R0, R0, #4\n"
        "BLX     R3\n"
        "LDR     R0, [SP,#0x1C]\n"
        "BL      sub_FF8C2550    \n"
        "LDR     R0, [SP,#0x1C]\n"
        "LDR     R1, [R0,#0x7C]\n"
        "LDR     R3, [R0,#0x94]\n"
        "LDR     R2, [R0,#0x98]\n"
        "ADD     R0, R0, #4\n"
        "BLX     R3\n"
        "B       loc_FF8C13B8\n"
"loc_FF8C10C0:\n"
        "CMP     R1, #0x13\n"
        "CMPNE   R1, #0x14\n"
        "CMPNE   R1, #0x15\n"
        "CMPNE   R1, #0x16\n"
        "BNE     loc_FF8C1178\n"
        "ADD     R3, SP, #0xC\n"
        "MOV     R2, SP\n"
        "ADD     R1, SP, #0x10\n"
        "BL      sub_FF8BFA8C    \n"
        "CMP     R0, #1\n"
        "MOV     R4, R0\n"
        "CMPNE   R4, #5\n"
        "BNE     loc_FF8C1114\n"
        "LDR     R0, [SP,#0x1C]\n"
        "MOV     R2, R4\n"
        "LDR     R1, [R0,#0x7C]!\n"
        "LDR     R12, [R0,#0x10]!\n"
        "LDR     R3, [R0,#4]\n"
        "MOV     R0, SP\n"
        "BLX     R12\n"
        "B       loc_FF8C114C\n"
"loc_FF8C1114:\n"
        "LDR     R0, [SP,#0x1C]\n"
        "CMP     R4, #2\n"
        "LDR     R3, [R0,#0x90]\n"
        "CMPNE   R4, #6\n"
        "BNE     loc_FF8C1160\n"
        "LDR     R12, [R0,#0x8C]\n"
        "MOV     R0, SP\n"
        "MOV     R2, R4\n"
        "MOV     R1, #1\n"
        "BLX     R12\n"
        "LDR     R0, [SP,#0x1C]\n"
        "MOV     R2, SP\n"
        "ADD     R1, SP, #0x10\n"
        "BL      sub_FF8C0B38    \n"
"loc_FF8C114C:\n"
        "LDR     R0, [SP,#0x1C]\n"
        "LDR     R2, [SP,#0xC]\n"
        "MOV     R1, R4\n"
        "BL      sub_FF8C0DD0    \n"
        "B       loc_FF8C13B8\n"
"loc_FF8C1160:\n"
        "LDR     R1, [R0,#0x7C]\n"
        "LDR     R12, [R0,#0x8C]\n"
        "ADD     R0, R0, #4\n"
        "MOV     R2, R4\n"
        "BLX     R12\n"
        "B       loc_FF8C13B8\n"
"loc_FF8C1178:\n"
        "CMP     R1, #0x22\n"
        "CMPNE   R1, #0x23\n"
        "BNE     loc_FF8C11C4\n"
        "LDR     R1, [R0,#0x7C]\n"
        "ADD     R1, R1, R1,LSL#1\n"
        "ADD     R1, R0, R1,LSL#2\n"
        "SUB     R1, R1, #8\n"
        "LDMIA   R1, {R2-R4}\n"
        "STMIA   R6, {R2-R4}\n"
        "BL      sub_FF8BECF4    \n"
        "LDR     R0, [SP,#0x1C]\n"
        "LDR     R1, [R0,#0x7C]\n"
        "LDR     R3, [R0,#0x8C]\n"
        "LDR     R2, [R0,#0x90]\n"
        "ADD     R0, R0, #4\n"
        "BLX     R3\n"
        "LDR     R0, [SP,#0x1C]\n"
        "BL      sub_FF8BEFF4    \n"
        "B       loc_FF8C13B8\n"
"loc_FF8C11C4:\n"
        "ADD     R1, R0, #4\n"
        "LDMIA   R1, {R2,R3,R12}\n"
        "STMIA   R6, {R2,R3,R12}\n"
        "LDR     R1, [R0]\n"
        "CMP     R1, #0x25\n"
        "ADDLS   PC, PC, R1,LSL#2\n"
        "B       loc_FF8C1398\n"
"loc_FF8C11E0:\n"
        "B       loc_FF8C1278\n"
"loc_FF8C11E4:\n"
        "B       loc_FF8C1278\n"
"loc_FF8C11E8:\n"
        "B       loc_FF8C1280\n"
"loc_FF8C11EC:\n"
        "B       loc_FF8C1288\n"
"loc_FF8C11F0:\n"
        "B       loc_FF8C1288\n"
"loc_FF8C11F4:\n"
        "B       loc_FF8C1288\n"
"loc_FF8C11F8:\n"
        "B       loc_FF8C1278\n"
"loc_FF8C11FC:\n"
        "B       loc_FF8C1280\n"
"loc_FF8C1200:\n"
        "B       loc_FF8C1288\n"
"loc_FF8C1204:\n"
        "B       loc_FF8C1288\n"
"loc_FF8C1208:\n"
        "B       loc_FF8C12A0\n"
"loc_FF8C120C:\n"
        "B       loc_FF8C12A0\n"
"loc_FF8C1210:\n"
        "B       loc_FF8C138C\n"
"loc_FF8C1214:\n"
        "B       loc_FF8C1394\n"
"loc_FF8C1218:\n"
        "B       loc_FF8C1394\n"
"loc_FF8C121C:\n"
        "B       loc_FF8C1394\n"
"loc_FF8C1220:\n"
        "B       loc_FF8C1394\n"
"loc_FF8C1224:\n"
        "B       loc_FF8C1398\n"
"loc_FF8C1228:\n"
        "B       loc_FF8C1398\n"
"loc_FF8C122C:\n"
        "B       loc_FF8C1398\n"
"loc_FF8C1230:\n"
        "B       loc_FF8C1398\n"
"loc_FF8C1234:\n"
        "B       loc_FF8C1398\n"
"loc_FF8C1238:\n"
        "B       loc_FF8C1398\n"
"loc_FF8C123C:\n"
        "B       loc_FF8C1290\n"
"loc_FF8C1240:\n"
        "B       loc_FF8C1298\n"
"loc_FF8C1244:\n"
        "B       loc_FF8C1298\n"
"loc_FF8C1248:\n"
        "B       loc_FF8C12AC\n"
"loc_FF8C124C:\n"
        "B       loc_FF8C12AC\n"
"loc_FF8C1250:\n"
        "B       loc_FF8C12B4\n"
"loc_FF8C1254:\n"
        "B       loc_FF8C12E4\n"
"loc_FF8C1258:\n"
        "B       loc_FF8C1314\n"
"loc_FF8C125C:\n"
        "B       loc_FF8C1344\n"
"loc_FF8C1260:\n"
        "B       loc_FF8C1374\n"
"loc_FF8C1264:\n"
        "B       loc_FF8C1374\n"
"loc_FF8C1268:\n"
        "B       loc_FF8C1398\n"
"loc_FF8C126C:\n"
        "B       loc_FF8C1398\n"
"loc_FF8C1270:\n"
        "B       loc_FF8C137C\n"
"loc_FF8C1274:\n"
        "B       loc_FF8C1384\n"
"loc_FF8C1278:\n"
        "BL      sub_FF8BDAE0\n"
        "B       loc_FF8C1398\n"
"loc_FF8C1280:\n"
        "BL      sub_FF8BDD64\n"
        "B       loc_FF8C1398\n"
"loc_FF8C1288:\n"
        "BL      sub_FF8BDF6C\n"
        "B       loc_FF8C1398\n"
"loc_FF8C1290:\n"
        "BL      sub_FF8BE1E4\n"
        "B       loc_FF8C1398\n"
"loc_FF8C1298:\n"
        "BL      sub_FF8BE3DC\n"
        "B       loc_FF8C1398\n"
"loc_FF8C12A0:\n" // ; jumptable FF8C11D8 entries 10,11
        //"BL      sub_FF8BE698\n"
		"BL      sub_FF8BE698_my\n" // -------------->
        "MOV     R4, #0\n"
        "B       loc_FF8C1398\n"
"loc_FF8C12AC:\n"
        "BL      sub_FF8BE7D8\n"
        "B       loc_FF8C1398\n"
"loc_FF8C12B4:\n"
        "LDRH    R1, [R0,#4]\n"
        "STRH    R1, [SP,#0x10]\n"
        "LDRH    R1, [R5,#2]\n"
        "STRH    R1, [SP,#0x12]\n"
        "LDRH    R1, [R5,#4]\n"
        "STRH    R1, [SP,#0x14]\n"
        "LDRH    R1, [R5,#6]\n"
        "STRH    R1, [SP,#0x16]\n"
        "LDRH    R1, [R0,#0xC]\n"
        "STRH    R1, [SP,#0x18]\n"
        "BL      sub_FF8C21FC    \n"
        "B       loc_FF8C1398\n"
"loc_FF8C12E4:\n"
        "LDRH    R1, [R0,#4]\n"
        "STRH    R1, [SP,#0x10]\n"
        "LDRH    R1, [R5,#2]\n"
        "STRH    R1, [SP,#0x12]\n"
        "LDRH    R1, [R5,#4]\n"
        "STRH    R1, [SP,#0x14]\n"
        "LDRH    R1, [R5,#6]\n"
        "STRH    R1, [SP,#0x16]\n"
        "LDRH    R1, [R5,#8]\n"
        "STRH    R1, [SP,#0x18]\n"
        "BL      sub_FF8C2368    \n"
        "B       loc_FF8C1398\n"
"loc_FF8C1314:\n"
        "LDRH    R1, [R5]\n"
        "STRH    R1, [SP,#0x10]\n"
        "LDRH    R1, [R0,#6]\n"
        "STRH    R1, [SP,#0x12]\n"
        "LDRH    R1, [R5,#4]\n"
        "STRH    R1, [SP,#0x14]\n"
        "LDRH    R1, [R5,#6]\n"
        "STRH    R1, [SP,#0x16]\n"
        "LDRH    R1, [R5,#8]\n"
        "STRH    R1, [SP,#0x18]\n"
        "BL      sub_FF8C2414    \n"
        "B       loc_FF8C1398\n"
"loc_FF8C1344:\n"
        "LDRH    R1, [R5]\n"
        "STRH    R1, [SP,#0x10]\n"
        "LDRH    R1, [R5,#2]\n"
        "STRH    R1, [SP,#0x12]\n"
        "LDRH    R1, [R5,#4]\n"
        "STRH    R1, [SP,#0x14]\n"
        "LDRH    R1, [R5,#6]\n"
        "STRH    R1, [SP,#0x16]\n"
        "LDRH    R1, [R0,#0xC]\n"
        "STRH    R1, [SP,#0x18]\n"
        "BL      sub_FF8C24B4    \n"
        "B       loc_FF8C1398\n"
"loc_FF8C1374:\n"
        "BL      sub_FF8BEB30\n"
        "B       loc_FF8C1398\n"
"loc_FF8C137C:\n"
        "BL      sub_FF8BF0F8\n"
        "B       loc_FF8C1398\n"
"loc_FF8C1384:\n"
        "BL      sub_FF8BF334\n"
        "B       loc_FF8C1398\n"
"loc_FF8C138C:\n"
        "BL      sub_FF8BF4B0\n"
        "B       loc_FF8C1398\n"
"loc_FF8C1394:\n"
        "BL      sub_FF8BF64C\n"
"loc_FF8C1398:\n"
        "LDR     R0, [SP,#0x1C]\n"
        "LDR     R1, [R0,#0x7C]\n"
        "LDR     R3, [R0,#0x8C]\n"
        "LDR     R2, [R0,#0x90]\n"
        "ADD     R0, R0, #4\n"
        "BLX     R3\n"
        "CMP     R4, #1\n"
        "BNE     loc_FF8C1400\n"
"loc_FF8C13B8:\n"
        "LDR     R0, [SP,#0x1C]\n"
        "MOV     R2, #0xC\n"
        "LDR     R1, [R0,#0x7C]\n"
        "ADD     R1, R1, R1,LSL#1\n"
        "ADD     R0, R0, R1,LSL#2\n"
        "SUB     R4, R0, #8\n"
        "LDR     R0, =0x4372C\n"
        "ADD     R1, SP, #0x10\n"
        "BL      sub_FFB34C1C\n"
        "LDR     R0, =0x43738\n"
        "MOV     R2, #0xC\n"
        "ADD     R1, SP, #0x10\n"
        "BL      sub_FFB34C1C\n"
        "LDR     R0, =0x43744\n"
        "MOV     R2, #0xC\n"
        "MOV     R1, R4\n"
        "BL      sub_FFB34C1C\n"
        "B       loc_FF8C1478\n"
"loc_FF8C1400:\n"
        "LDR     R0, [SP,#0x1C]\n"
        "LDR     R0, [R0]\n"
        "CMP     R0, #0xB\n"
        "BNE     loc_FF8C1448\n"
        "MOV     R3, #0\n"
        "STR     R3, [SP]\n"
        "MOV     R3, #1\n"
        "MOV     R2, #1\n"
        "MOV     R1, #1\n"
        "MOV     R0, #0\n"
        "BL      sub_FF8BD8E8\n"
        "MOV     R3, #0\n"
        "STR     R3, [SP]\n"
        "MOV     R3, #1\n"
        "MOV     R2, #1\n"
        "MOV     R1, #1\n"
        "MOV     R0, #0\n"
        "B       loc_FF8C1474\n"
"loc_FF8C1448:\n"
        "MOV     R3, #1\n"
        "MOV     R2, #1\n"
        "MOV     R1, #1\n"
        "MOV     R0, #1\n"
        "STR     R3, [SP]\n"
        "BL      sub_FF8BD8E8\n"
        "MOV     R3, #1\n"
        "MOV     R2, #1\n"
        "MOV     R1, #1\n"
        "MOV     R0, #1\n"
        "STR     R3, [SP]\n"
"loc_FF8C1474:\n"
        "BL      sub_FF8BDA28\n"
"loc_FF8C1478:\n"
        "LDR     R0, [SP,#0x1C]\n"
        "BL      sub_FF8C2188    \n"
        "B       loc_FF8C0EA0\n"

);
};

void __attribute__((naked,noinline)) sub_FF8BE698_my(){
 asm volatile(
        "STMFD   SP!, {R4-R8,LR}\n"
        "LDR     R7, =0x4440\n"
        "MOV     R4, R0\n"
        "LDR     R0, [R7,#0x1C]\n"
        "MOV     R1, #0x3E\n"
        "BL      sub_FF884940\n"
        "LDRSH   R0, [R4,#4]\n"
        "MOV     R2, #0\n"
        "MOV     R1, #0\n"
        "BL      sub_FF8BD64C\n"
        "MOV     R6, R0\n"
        "LDRSH   R0, [R4,#6]\n"
        "BL      sub_FF8BD75C\n"
        "LDRSH   R0, [R4,#8]\n"
        "BL      sub_FF8BD7B4\n"
        "LDRSH   R0, [R4,#0xA]\n"
        "BL      sub_FF8BD80C\n"
        "LDRSH   R0, [R4,#0xC]\n"
        "MOV     R1, #0\n"
        "BL      sub_FF8BD864\n"
        "MOV     R5, R0\n"
        "LDR     R0, [R4]\n"
        "LDR     R8, =0x43744\n"
        "CMP     R0, #0xB\n"
        "MOVEQ   R6, #0\n"
        "MOVEQ   R5, #0\n"
        "BEQ     loc_FF8BE72C\n"
        "CMP     R6, #1\n"
        "BNE     loc_FF8BE72C\n"
        "LDRSH   R0, [R4,#4]\n"
        "LDR     R1, =0xFF8BD5B8\n"
        "MOV     R2, #2\n"
        "BL      sub_FF95989C    \n"
        "STRH    R0, [R4,#4]\n"
        "MOV     R0, #0\n"
        "STR     R0, [R7,#0x28]\n"
        "B       loc_FF8BE734\n"
"loc_FF8BE72C:\n"
        "LDRH    R0, [R8]\n"
        "STRH    R0, [R4,#4]\n"
"loc_FF8BE734:\n"
        "CMP     R5, #1\n"
        "LDRNEH  R0, [R8,#8]\n"
        "BNE     loc_FF8BE750\n"
        "LDRSH   R0, [R4,#0xC]\n"
        "LDR     R1, =0xFF8BD63C\n"
        "MOV     R2, #0x20\n"
        "BL      sub_FF8C21B8\n"
"loc_FF8BE750:\n"
        "STRH    R0, [R4,#0xC]\n"
        "LDRSH   R0, [R4,#6]\n"
        //"BL      sub_FF8B079C    \n"
		"BL      sub_FF8B079C_my    \n" // ------------------------->
        "LDRSH   R0, [R4,#8]\n"
        "MOV     R1, #1\n"
        "BL      sub_FF8B0EEC    \n"
        "MOV     R1, #0\n"
        "ADD     R0, R4, #8\n"
        "BL      sub_FF8B0F74    \n"
        "LDRSH   R0, [R4,#0xE]\n"
        "BL      sub_FF8B8A58    \n"
        "LDR     R4, =0xBB8\n"
        "CMP     R6, #1\n"
        "BNE     loc_FF8BE7A8\n"
        "LDR     R0, [R7,#0x1C]\n"
        "MOV     R2, R4\n"
        "MOV     R1, #2\n"
        "BL      sub_FF88484C    \n"
        "TST     R0, #1\n"
        "LDRNE   R1, =0x5A3\n"
        "LDRNE   R0, =0xFF8BDC38\n"
        "BLNE    sub_FF81E88C\n"
"loc_FF8BE7A8:\n"
        "CMP     R5, #1\n"
        "LDMNEFD SP!, {R4-R8,PC}\n"
        "LDR     R0, [R7,#0x1C]\n"
        "MOV     R2, R4\n"
        "MOV     R1, #0x20\n"
        "BL      sub_FF88484C    \n"
        "TST     R0, #1\n"
        "LDRNE   R1, =0x5A8\n"
        "LDRNE   R0, =0xFF8BDC38\n"
        "LDMNEFD SP!, {R4-R8,LR}\n"
        "BNE     sub_FF81E88C\n"
        "LDMFD   SP!, {R4-R8,PC}\n"
 );
};

void __attribute__((naked,noinline)) sub_FF8B079C_my()
{  
 asm volatile(
        "STMFD   SP!, {R4-R6,LR}\n"
        "LDR     R5, =0x4150\n"
        "MOV     R4, R0\n"
        "LDR     R0, [R5,#4]\n"
        "CMP     R0, #1\n"
        "LDRNE   R1, =0x146\n"
        "LDRNE   R0, =0xFF8B05A0\n"
        "BLNE    sub_FF81E88C\n"
        "CMN     R4, #0xC00\n"
        "LDREQSH R4, [R5,#2]\n"
        "CMN     R4, #0xC00\n"
        "MOVEQ   R1, #0x14C\n"
        "LDREQ   R0, =0xFF8B05A0\n"
        "STRH    R4, [R5,#2]\n"
        "BLEQ    sub_FF81E88C\n"
        "MOV     R0, R4\n"

        //"BL      sub_FFA0D7FC\n" // -
		"BL      apex2us\n"  // +

        "MOV     R4, R0\n"
        "BL      sub_FF8F526C\n"
        "MOV     R0, R4\n"
        "BL      sub_FF8FE138\n"
        "TST     R0, #1\n"
        "LDRNE   R1, =0x151\n"
        "LDMNEFD SP!, {R4-R6,LR}\n"
        "LDRNE   R0, =0xFF8B05A0\n"
        "BNE     sub_FF81E88C\n"
        "LDMFD   SP!, {R4-R6,PC}\n"
     );
};
